home *** CD-ROM | disk | FTP | other *** search
- /*
- main.c
-
- by Alex D. Chaffee (adc)
- (chaffee@reed.bitnet, AOL:AlexCh, CIS:71210,1117)
-
- Copyright © 1991 Alex Chaffee. Permission granted to change and
- distribute freely, provided all changes are documented.
-
- protoclip fkey (+ app)
- */
-
- #include "config.h" /* There is a different copy of this file
- for the application and fkey projects.
- Each contains specific #defines.
- */
- #ifdef FKEY
- #include <SetUpA4.h>
- #else
- #include <stdio.h>
- #include <console.h>
- #include <profile.h>
- #endif
- #include "main.h"
- #include "proto.h"
- #include "hfile.h"
-
- void main(void);
- #ifdef DEBUG
- void DebugNum(long e);
- #endif
-
- #ifdef DEBUG
- #define CheckHeap(); \
- NewHandle(0); asm{nop};
- #else
- #define CheckHeap()
- #endif
-
- void main(void)
- {
- Handle handIn, handOut;
- long lenIn, lenOut;
- long offset;
- Boolean fOkay;
-
- #ifdef FKEY
- RememberA0();
- SetUpA4();
- #endif
-
- #ifdef APP
- console_options.nrows = 14;
- printf("Protoclip!\n");
- #endif
- #ifdef PROFILE
- printf("Profiling...\n");
- InitProfile(200,200);
- #endif
-
- SetCursor(*GetCursor(watchCursor));
- ShowCursor();
-
- LoadScrap();
-
- /* If we're running as an application, just take the system clipboard */
- #ifndef APP
- if (0L < TEGetScrapLen()) { /* if we're using the TE Scrap */
- ZeroScrap();
- TEToScrap();
- }
- #endif
- if (0L == (handIn = NewHandle(0L)) ||
- 0L >= (lenIn = GetScrap(handIn,'TEXT',&offset))) {
- DisposHandle(handIn);
- SysBeep(10);
- goto leave;
- }
-
- handOut = NewHandle(0);
-
- fOkay = proto(handIn, handOut) == 0;
-
- HUnlock(handIn);
- DisposHandle(handIn);
-
- /* DebugNum((long)*handOut); */
-
- if (fOkay)
- {
- HLock(handOut);
-
- ZeroScrap();
-
- lenOut = GetHandleSize(handOut);
-
- PutScrap(lenOut ,'TEXT', *handOut);
-
- if (0L < TEGetScrapLen())
- TEFromScrap();
- }
- else
- SysBeep(8);
-
- #ifdef APP
- /* print contents of handOut */
- {
- long i;
- char ch;
- HLock(handOut);
- CheckHeap();
- for (i=0; i<GetHandleSize(handOut); ++i)
- {
- CheckHeap();
- ch = *((*handOut)+i);
- CheckHeap();
- if (ch == '\r') putchar('\n');
- else putchar(ch);
- }
- CheckHeap();
- putchar('\n');
- }
- #endif
-
- HUnlock(handOut);
- DisposHandle(handOut);
-
- leave:
- InitCursor();
-
- #ifdef FKEY
- RestoreA4();
- #endif
- return;
- }
-
- #ifdef DEBUG
- void DebugNum(long e)
- {
- Str255 st;
- NumToString(e, st);
- DebugStr(st);
- }
- #endif
-